home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #3 / Amiga Plus CD - 2002 - No. 03.iso / AmigaPlus / AmigaOS / SDL_Teil1 / SDL1 / drittes.c next >
Encoding:
C/C++ Source or Header  |  2003-02-23  |  1.4 KB  |  62 lines

  1. #include <stdlib.h>
  2. #include "SDL.h"
  3.  
  4. int main()
  5. {
  6.   /* reserviere datenstrukturen für Video*/
  7.   SDL_Surface *display;
  8.   SDL_Surface *image;
  9.   SDL_Rect source;
  10.   SDL_Rect target;
  11.   int vm;
  12.  
  13.   /* initialisiere SDL */
  14.   if (SDL_Init(SDL_INIT_VIDEO) < 0)
  15.   {
  16.     printf("SDL konnte nicht initialisiert werden: %s\n", SDL_GetError());
  17.     exit(-1);
  18.   }
  19.   printf("SDL erfolgreich initialisiert!\n");
  20.  
  21.   /* lege Bildschirmgröße fest */
  22.   vm = SDL_VideoModeOK(640, 512, 8, SDL_HWSURFACE);
  23.   if (vm == 0) vm = SDL_VideoModeOK(640, 512, 8, SDL_SWSURFACE);
  24.   printf("mögliche Farbtiefe: %d\n", vm);
  25.   if (vm > 0)
  26.   {
  27.     display = SDL_SetVideoMode(640, 512, vm, SDL_HWSURFACE);
  28.   }
  29.   else
  30.   {
  31.     printf("Konnte kein Display der Auflösung 640 x 512 öffnen: %s\n", SDL_GetError());
  32.     exit(-1);
  33.   }
  34.  
  35.   /* lade Bild in SDL_Surface */
  36.   image = SDL_LoadBMP("SDL_Title.bmp");
  37.   if (image == NULL)
  38.   {
  39.     printf("Konnte Bild nicht laden: %s\n",  SDL_GetError());
  40.   }
  41.  
  42.   /* definiere Quell- und Zielbereich */
  43.   source.x = 0;
  44.   source.y = 0;
  45.   source.w = (image->w)/2; 
  46.   source.h = (image->h)/2;
  47.   target.x = 100;
  48.   target.y = 100;
  49.   target.w = (image->w)/2;
  50.   target.h = (image->h)/2;
  51.  
  52.   /* zeige Bild an */
  53.   SDL_BlitSurface(image, &source, display, &target);
  54.   SDL_UpdateRects(display, 1, &target);
  55.   SDL_Delay(3000);
  56.   SDL_FreeSurface(image);
  57.  
  58.   /* räume SDL auf */
  59.   printf("Verlasse SDL...\n");
  60.   atexit(SDL_Quit);
  61. }
  62.